<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>

<body>
	<script type="text/javascript">

		/*
			promise三种状态：pending 待定/进行中 fulfilled 已成功 rejected 已失败
			语法：const p = new Promise(function(resolve,reject) {
				resolve:将promise对象状态从进行中修改成已完成 将成功的结果返回出去
				reject:将promise对象状态从进行中修改成已失败 将失败的结果返回出去
	
		
		}) 
		一旦状态被修改（pending==>fulfilled/rejected）,不会再改变
		*/
		const p = new Promise(function (resolve, reject) {
			if (Math.random() < 0.5) {
				resolve('success')
			} else {
				reject('false')
			}

		})
		console.log(p)
		//箭头函数：替代匿名函数

		/*const fn = function() {
	
		}
		const fn = (a,b) =>{
			console.log(a,b)
		}*/
		// setTimeout(function() {})
		/*setTimeout(() =>{
	
		})*/
		//.then(成功状态的回调,失败状态的回调)成功的时候的结果
		//.catch() 接受失败的结果
		//.finally() 成功失败均执行
		/*	p.then( (res) => {
				console.log(res)
			},(err) =>{
				console.log(err)
			})*/
		p.then((res) => {
			console.log(res)
		})
			.catch((err) => {
				console.log(err)
			})
			.finally(() => {
				console.log('执行完毕')
			})
	</script>
</body>

</html>